export default function httpXhr(option) {
    let _this = this;
    const curPormise = new Promise((resolve,reject)=>{
        let xhr = new XMLHttpRequest();
        // 当上传完成时调用
        xhr.onload = function() {
            if (xhr.status === 200) {
                const index = _this.uploadFiles.findIndex(item => item.hash === hash);
                //大文件上传进度
                _this.uploadQuantity ++;  //有bug，需要重置后续记得补充逻辑
                _this.$set(_this.uploadFiles,index,{..._this.uploadFiles[index],...{status: 'uploading',percentage:_this.uploadQuantity / totalChunck * 100}});
                _this.onProgress(file,_this.uploadQuantity / totalChunck * 100);
                return resolve(nowChunck);
            }
        }
        xhr.onerror = function(e) {
            _this.errorChuncks.push({file:file,nowChunck,totalChunck,hash});
            return reject(hash);
        }
        // 发送请求
        xhr.open('POST', _this.uploadApi, true);
        if (_this.apiHeader?.withCredentials && 'withCredentials' in xhr) {
            xhr.withCredentials = true;
        }
        const headers = _this.apiHeader || {};
        for (let item in headers) {
            if (headers.hasOwnProperty(item) && headers[item] !== null) {
                xhr.setRequestHeader(item, headers[item]);
            }
        }
        xhr.send(file);
    })
    _this.promiseArr.push(curPormise);
}